#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::WidgetClass())
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_ClearText_clicked()
{
    ui->plainTextEdit->clear();
}

void Widget::on_pushButton_ClearItems_clicked()
{
    ui->comboBox_Items->clear();
}

void Widget::on_pushButton_InitItems_clicked()
{
    ui->comboBox_Items->clear();
    QIcon icon;
    icon.addFile(":/Widget/resource/积木380X380.jpg");
    for (int i = 0; i < 20; i++)
    {
        ui->comboBox_Items->addItem(icon, QString("Item %1").arg(i));
    }

}

void Widget::on_checkBox_Editable_clicked(bool checked)
{
    ui->comboBox_Items->setEditable(checked);
}

void Widget::on_pushButton_InitCities_clicked()
{
    ui->comboBox_Cities->clear();

    QMap<QString, int> city_zone;
    city_zone.insert("京城", 11);
    city_zone.insert("魔都", 12);
    city_zone.insert("神都", 31);
    city_zone.insert("古都", 14);

    foreach (const QString &str, city_zone.keys() )
    {
        ui->comboBox_Cities->addItem(str, city_zone.value(str));
    }

}

void Widget::on_comboBox_Cities_currentIndexChanged(int index)
{
    QString str = ui->comboBox_Cities->currentText() + ui->comboBox_Cities->currentData().toString();
    ui->plainTextEdit->appendPlainText("内容" + str + "索引:" + QString::number(index));
}
